package com.stlm2.dems.service;

import com.stlm2.core.common.page.PageView;
import com.stlm2.dems.dao.*;
import com.stlm2.dems.entity.*;
import com.stlm2.util.Memcached;
import com.stlm2.util.codecontent.CodeContent;
import org.apache.commons.lang.math.NumberUtils;
import org.json.JSONObject;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;

import com.stlm2.core.base.BaseDao;
import com.stlm2.core.base.impl.BaseServiceImpl;
import org.springframework.ui.ModelMap;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service("ddmShoppingCartService")
@Transactional(rollbackForClassName={"java.lang.Exception"}, propagation = Propagation.REQUIRED)
public class DdmShoppingCartService extends BaseServiceImpl<DdmShoppingCart> {

	@Resource
	private DdmShoppingCartDao ddmShoppingCartDao;

	@Resource
	private UserDao userDao;
	@Resource
	private DdmGoodsDao ddmGoodsDao;
	@Resource
	private SpecificationDao specificationDao;

	@Resource
	private GoodSpecificationDao goodSpecificationDao;
	@Resource
	private Memcached memcached;
	@Resource
	private DdmShopDao ddmShopDao;
	@Resource
	private GoodsValueAddedServicesDao goodsValueAddedServicesDao;
	@Resource
	private ValueAddedServicesDao valueAddedServicesDao;
	@Resource
	private  CollectionsDao collectionsDao;
	@Override
	protected BaseDao <DdmShoppingCart> getDao() {
		return ddmShoppingCartDao;
	}

	/*
	*zlq
	* 用户获取购物车信息
	*  @param  token
	*  @param  isSettlement:是否结算
	 */
	public  String getUserShoppingCart(ModelMap model, String token, boolean isSettlement){

		if (StringUtils.isEmpty(token)) {
			return CodeContent.getModelByCode(-1, "", model);
		}
		User loginUser = userDao.getByToken(token);
		if (loginUser == null) {
			return CodeContent.getModelByCode(-1, "", model);
		}
		DdmShoppingCart shoppingCart =new DdmShoppingCart();
		shoppingCart.setUserId(loginUser.getId());
		if(isSettlement){
			shoppingCart.setShoppingCartState(ShoppingCartState.Valid);
		}else {
			List<String > shoppingCartStateList =new ArrayList<String>();
			shoppingCartStateList.add(String.valueOf(ShoppingCartState.Valid.getIntValue()));
			shoppingCartStateList.add(String.valueOf(ShoppingCartState.NotSet.getIntValue()));
			shoppingCartStateList.add(String.valueOf(ShoppingCartState.NoSelect.getIntValue()));
			shoppingCart.setShoppingCartStateList(shoppingCartStateList);
		}
		PageView pageView=ddmShoppingCartDao.queryPageView(-1, -1,shoppingCart);
		List<ModelMap>  modelMapList1=convertList(pageView.getRecords());
		BigDecimal totalMoney =new BigDecimal("0.00");
		int selectCount=0;
		for(int i=0;i<modelMapList1.size();i++){
			if(modelMapList1.get(i).get("isSelect").toString().equals("true")){
				BigDecimal totalMoney1 =new BigDecimal(modelMapList1.get(i).get("memberPrice").toString());
				totalMoney1=totalMoney1.multiply(new BigDecimal(modelMapList1.get(i).get("count").toString()));
				totalMoney=totalMoney.add(totalMoney1);
				selectCount++;
				List<ModelMap>  valueAddedServicesList= (List<ModelMap>)modelMapList1.get(i).get("valueAddedServicesList");
				for(int x=0;x<valueAddedServicesList.size();x++){
					if(valueAddedServicesList.get(x).get("isSelect").toString().equals("true")){
						BigDecimal totalMoney2 =new BigDecimal(valueAddedServicesList.get(x).get("price").toString());
						totalMoney=totalMoney.add(totalMoney2);
					}
				}
			}

		}
		model.put("datas",modelMapList1);
		model.put("totalMoney",totalMoney);
		model.put("rowCount",selectCount);
		model.put("code",1);
		model.put("msg","success");
		return  new JSONObject(model).toString();
	}

	public List<ModelMap> convertList(List<DdmShoppingCart> shoppingCartList) {
		List<ModelMap> list = new ArrayList<ModelMap>();
		if (shoppingCartList != null && shoppingCartList.size() > 0) {
			for (DdmShoppingCart ddmShoppingCart : shoppingCartList) {
				ModelMap map = buildModelList(ddmShoppingCart);
				list.add(map);
			}
		}
		return list;
	}
	public ModelMap buildModelList(DdmShoppingCart ddmShoppingCart) {
		ModelMap model = new ModelMap();
		DdmGoods ddmGoods=ddmGoodsDao.getById(ddmShoppingCart.getGoodsId());
		String mainImg=ddmGoods.getMainImg().split(",")[0];
		if(!StringUtils.isEmpty(ddmShoppingCart.getSpecificationId())){
			GoodSpecification goodSpecification=goodSpecificationDao.getById(ddmShoppingCart.getSpecificationId());
			model.put("goodSpecificationName",goodSpecification.getPropertiesName());
			model.put("memberPrice",goodSpecification.getMemberPrice());
			model.put("specificationId",goodSpecification.getId());
			mainImg=goodSpecification.getImage().split(",")[0];
			if(!goodSpecification.getGoodsState()){
				if(ddmGoods.getState()){
					ddmGoods.setState(false);
				}
			}
		}else {
			model.put("specificationId","");
			model.put("goodSpecificationName","");
			model.put("memberPrice",ddmGoods.getMemberPrice());
		}
		if(!ddmGoods.getState()){
			if(ddmShoppingCart.getShoppingCartState()!=ShoppingCartState.NoSelect){
				ddmShoppingCart.setShoppingCartState(ShoppingCartState.NoSelect);
				ddmShoppingCartDao.modify(ddmShoppingCart);
			}
		}else {
			if(ddmShoppingCart.getShoppingCartState()==ShoppingCartState.NoSelect){
				ddmShoppingCart.setShoppingCartState(ShoppingCartState.NotSet);
				ddmShoppingCartDao.modify(ddmShoppingCart);
			}
		}
		model.put("cartid",ddmShoppingCart.getId());
		model.put("goodsName",ddmGoods.getName());
		model.put("goodsId",ddmGoods.getId());
		model.put("goodsCode",ddmGoods.getCode());
		model.put("goodsState",ddmGoods.getState()!=null?ddmGoods.getState():false);
		model.put("mainImg",mainImg);
		model.put("count",ddmShoppingCart.getCount());

		model.put("isSelect",ddmShoppingCart.getShoppingCartState().equals(ShoppingCartState.Valid)?true:false);
		List<ValueAddedServices> valueAddedServicesList =valueAddedServicesDao.getByGoodsId(ddmGoods.getId());
		model.put("valueAddedServicesList",convertValueAddedServicesList(valueAddedServicesList,ddmShoppingCart));
		List <Collections>  collectionsList=collectionsDao.getByGoodsId(ddmShoppingCart.getUserId(),ddmGoods.getId());
		model.put("collectionsId",collectionsList.size()!=0?collectionsList.get(0).getId():"");
		model.put("ifCollections",collectionsList.size()!=0?true:false);
		model.put("shoppingCartStateValue",ddmShoppingCart.getShoppingCartStateValue());

		return  model;
	}

	public List<ModelMap> convertValueAddedServicesList(List<ValueAddedServices> valueAddedServicesList,DdmShoppingCart ddmShoppingCart) {
		List<ModelMap> list = new ArrayList<ModelMap>();
		if (valueAddedServicesList != null && valueAddedServicesList.size() > 0) {
			for (ValueAddedServices valueAddedServices : valueAddedServicesList) {
				ModelMap map = buildModelValueAddedServicesList(valueAddedServices,ddmShoppingCart);
				list.add(map);
			}
		}
		return list;
	}

	public ModelMap buildModelValueAddedServicesList(ValueAddedServices valueAddedServices,DdmShoppingCart ddmShoppingCart) {
		ModelMap model = new ModelMap();
		model.put("id",valueAddedServices.getId());
		model.put("name",valueAddedServices.getName());
		model.put("detailsUrl",valueAddedServices.getDetailsUrl());
		model.put("price",valueAddedServices.getPrice());
		if(!StringUtils.isEmpty(ddmShoppingCart.getValueAddedServicesIds())){
			String []selectIds=ddmShoppingCart.getValueAddedServicesIds().split(",");
			List <String > selectIdList=new ArrayList<String>();
			for(String selectId:selectIds){
				selectIdList.add(selectId);
			}
			if(selectIdList.contains(String.valueOf(valueAddedServices.getId()))){
				model.put("isSelect",true);
			}else {
				model.put("isSelect",false);
			}
		}else {
			model.put("isSelect",false);
		}
		return  model;
	}



	/*
	*zlq
	* 用户添加购物车
	*  @param  token
	*  @param  goodsId：商品ID
	*  @param count ：数量
	*  @param  specificationId：规格ID（无规格时，可为空）
	*  @param valueAddedServicesIds:增值服务ID，（没有可为空，多个用，隔开）
	 */
	public  String addUserShoppingCart(ModelMap model, String token,String goodsId,String count,String specificationId,String valueAddedServicesIds){

		DdmShoppingCart shoppingCart =new DdmShoppingCart();
		if (StringUtils.isEmpty(token)) {
			return CodeContent.getModelByCode(-1, "", model);
		}
		User loginUser = userDao.getByToken(token);
		if (loginUser == null) {
			return CodeContent.getModelByCode(-1, "", model);
		}
		if (!NumberUtils.isDigits(goodsId)) {
			return CodeContent.getModelByCode(0, "商品ID不能为空", model);
		}
		if (!NumberUtils.isDigits(count)) {
			return CodeContent.getModelByCode(0, "请输入数量", model);
		}
		if(Integer.parseInt(count)<1){
			return CodeContent.getModelByCode(0, "请输入数量", model);
		}
		DdmGoods goods=ddmGoodsDao.getById(Integer.parseInt(goodsId));
		if(goods==null){
			return CodeContent.getModelByCode(0, "找不到相应的商品", model);
		}
		if(goods.getState().equals(false)){
			return CodeContent.getModelByCode(0, "商品不是有效状态，无法添加购物车", model);
		}
		if (!StringUtils.isEmpty(valueAddedServicesIds)) {
			valueAddedServicesIds=removeRepetition(valueAddedServicesIds);
			String [] valueAddedServicesIds1=valueAddedServicesIds.split(",");
			for(String valueAddedServicesId:valueAddedServicesIds1){
				boolean goodServiceMatch=goodsValueAddedServicesDao.goodServiceMatch(goods.getId(),Integer.parseInt(valueAddedServicesId));
				if(!goodServiceMatch){
					return CodeContent.getModelByCode(0, "增值服务不匹配", model);
				}
			}
			shoppingCart.setValueAddedServicesIds(valueAddedServicesIds);
		}

		Specification specification = new Specification();
		specification.setGoodId(goods.getId());
		specification.setIsValid(true);
		List <Specification> specificationList=specificationDao.queryPageView(-1,-1,specification).getRecords();
		if(specificationList.size()>0){
			if (!NumberUtils.isDigits(specificationId)) {
				return CodeContent.getModelByCode(0, "请选择规格", model);
			}
			GoodSpecification goodSpecification=goodSpecificationDao.getById(Integer.parseInt(specificationId));
			if(goodSpecification==null){
				return CodeContent.getModelByCode(0, "不存在的规格", model);
			}
			if(!goodSpecification.getGoodsState()){
				return CodeContent.getModelByCode(0, "该规格产品不是有效的", model);
			}
			shoppingCart.setMemberPrice(goodSpecification.getMemberPrice());
			shoppingCart.setDdPrice(goodSpecification.getDdPrice());
			shoppingCart.setSpecificationId(goodSpecification.getId());
		}else {
			shoppingCart.setMemberPrice(goods.getMemberPrice());
			shoppingCart.setDdPrice(goods.getDdPrice());
		}
		shoppingCart.setUserId(loginUser.getId());
		shoppingCart.setGoodsId(goods.getId());
		List<String > shoppingCartStateList =new ArrayList<String>();
		shoppingCartStateList.add(String.valueOf(ShoppingCartState.Valid.getIntValue()));
		shoppingCartStateList.add(String.valueOf(ShoppingCartState.NotSet.getIntValue()));
		shoppingCart.setShoppingCartStateList(shoppingCartStateList);
		List<DdmShoppingCart>  shoppingCartList=ddmShoppingCartDao.queryPageView(-1,-1,shoppingCart).getRecords();
		if(shoppingCartList.size()>0){
			DdmShoppingCart shoppingCart2=shoppingCartList.get(0);
			int count2= shoppingCart2.getCount() +  Integer.parseInt(count);
			shoppingCart2.setCount(count2);
			ddmShoppingCartDao.modify(shoppingCart2);
			//拆分购物车
			separateDdmShoppingCart(shoppingCart2);
			return CodeContent.getModelByCode(1, "success", model);
		}
		shoppingCart.setShoppingCartState(ShoppingCartState.Valid);
		shoppingCart.setCount(Integer.parseInt(count));
		shoppingCart.setCreateUserId(loginUser.getId());
		shoppingCart.setCreateTime(new Date());

		ddmShoppingCartDao.add(shoppingCart);
		//拆分购物车
		separateDdmShoppingCart(shoppingCart);
		return CodeContent.getModelByCode(1, "success", model);
	}

	/*
	*zlq
	* 用户修改购物车
	*  @param  token
	*  @param  modifydata: 字符串拼接的数据： id=:count=:specificationId=:valueAddedServicesIds= 多组数据以; 隔开
	 */
	public  String modifyUserShoppingCart(ModelMap model, String token,String modifydata){
		if (StringUtils.isEmpty(token)) {
			return CodeContent.getModelByCode(-1, "", model);
		}
		User loginUser = userDao.getByToken(token);
		if (loginUser == null) {
			return CodeContent.getModelByCode(-1, "", model);
		}
		List <DdmShoppingCart> ddmShoppingCartList=new ArrayList<DdmShoppingCart>();
		String[] userShoppingCarts =modifydata.split(";");
		for(int i=0;i<userShoppingCarts.length;i++){
			String[] dates=userShoppingCarts[i].split(":");
			String [] idStr=dates[0].split("=");
			String [] countStr=dates[1].split("=");
			String [] specificationIdStr=dates[2].split("=");
			String [] alueAddedServicesIdsStr=dates[3].split("=");
			if(idStr.length!=2){
				return CodeContent.getModelByCode(0, "购物车ID不能为空", model);
			}
			DdmShoppingCart ddmShoppingCart=ddmShoppingCartDao.getById(Integer.parseInt(idStr[1]));
			if(ddmShoppingCart!=null){
				if(countStr.length!=2){
					return CodeContent.getModelByCode(0, "请选择数量", model);
				}
				if(Integer.parseInt(countStr[1])<1){
					return CodeContent.getModelByCode(0, "数量不能小于1", model);
				}
				ddmShoppingCart.setCount(Integer.parseInt(countStr[1]));

				Specification specification = new Specification();
				specification.setGoodId(ddmShoppingCart.getGoodsId());
				specification.setIsValid(true);
				List <Specification> specificationList=specificationDao.queryPageView(-1,-1,specification).getRecords();
				if(specificationList.size()>0){
					if (specificationIdStr.length!=2) {
						return CodeContent.getModelByCode(0, "请选择规格", model);
					}
					GoodSpecification goodSpecification=goodSpecificationDao.getById(Integer.parseInt(specificationIdStr[1]));
					if(goodSpecification==null){
						return CodeContent.getModelByCode(0, "不存在的规格", model);
					}
					if(!goodSpecification.getGoodsState()){
						return CodeContent.getModelByCode(0, "该规格产品不是有效的", model);
					}
					ddmShoppingCart.setSpecificationId(goodSpecification.getId());
					ddmShoppingCart.setDdPrice(goodSpecification.getDdPrice());
					ddmShoppingCart.setMemberPrice(goodSpecification.getMemberPrice());
				}else {
					DdmGoods ddmGoods=ddmGoodsDao.getById(ddmShoppingCart.getGoodsId());
					if(!ddmGoods.getState()){
						return CodeContent.getModelByCode(0, "商品已经无效", model);
					}
					ddmShoppingCart.setMemberPrice(ddmGoods.getMemberPrice());
					ddmShoppingCart.setDdPrice(ddmGoods.getDdPrice());
				}

				if (alueAddedServicesIdsStr.length==2) {
					String [] valueAddedServicesIds1=removeRepetition(alueAddedServicesIdsStr[1]).split(",");
					for(String valueAddedServicesId:valueAddedServicesIds1){
						boolean goodServiceMatch=goodsValueAddedServicesDao.goodServiceMatch(ddmShoppingCart.getGoodsId(),Integer.parseInt(valueAddedServicesId));
						if(!goodServiceMatch){
							return CodeContent.getModelByCode(0, "增值服务不匹配", model);
						}
					}
					ddmShoppingCart.setValueAddedServicesIds(removeRepetition(alueAddedServicesIdsStr[1]));
				}
				ddmShoppingCartList.add(ddmShoppingCart);
			}
		}
		for(DdmShoppingCart ddmShoppingCart :ddmShoppingCartList){
			ddmShoppingCartDao.modify(ddmShoppingCart);
			//拆分购物车
			separateDdmShoppingCart(ddmShoppingCart);
		}
		return CodeContent.getModelByCode(1, "success", model);
	}

	/*
	*zlq
	* 用户删除购物车
	*  @param  token
	*  @param  id:ID(多个ID用，拼接)
	 */
	public  String deleteUserShoppingCart(ModelMap model,String token,String id){
		if (StringUtils.isEmpty(token)) {
			return CodeContent.getModelByCode(-1, "", model);
		}
		User loginUser = userDao.getByToken(token);
		if (loginUser == null) {
			return CodeContent.getModelByCode(-1, "", model);
		}
		if (!StringUtils.isEmpty(id)) {
			String[] ids =id.split(",");
			for(int i=0;i<ids.length;i++){
				DdmShoppingCart shoppingCart =ddmShoppingCartDao.getById(Integer.parseInt(ids[i]));
				if(shoppingCart!=null){
					shoppingCart.setShoppingCartState(ShoppingCartState.Invalid);
					ddmShoppingCartDao.modify(shoppingCart);
				}
			}
		}

		return CodeContent.getModelByCode(1, "success", model);
	}


	/*
	*zlq
	* 用户选择购物车
	*  @param  token
	*  @param  id:ID
	*   @param  option:选项  true:选择 false：未选
	*   valueAddedServicesIds:增值服务拼接的字符串
	 */
	public  String optionCart(ModelMap model,String token,String id,boolean option,String valueAddedServicesIds){
		if (StringUtils.isEmpty(token)) {
			return CodeContent.getModelByCode(-1, "", model);
		}
		if(!StringUtils.isEmpty(valueAddedServicesIds)){
			valueAddedServicesIds=removeRepetition(valueAddedServicesIds);
			String [] servicesids=valueAddedServicesIds.split(",");
			for(String servicesid :servicesids){
				ValueAddedServices valueAddedServices=valueAddedServicesDao.getById(Integer.parseInt(servicesid));
				if(valueAddedServices==null){
					return CodeContent.getModelByCode(0, "增值服务不存在", model);
				}
			}
		}


		User loginUser = userDao.getByToken(token);
		if (loginUser == null) {
			return CodeContent.getModelByCode(-1, "", model);
		}
				DdmShoppingCart shoppingCart =ddmShoppingCartDao.getById(Integer.parseInt(id));
				if(shoppingCart!=null){
					if(!shoppingCart.getShoppingCartState().equals(ShoppingCartState.NoSelect)){
						if(option){
							shoppingCart.setShoppingCartState(ShoppingCartState.Valid);
							shoppingCart.setValueAddedServicesIds(valueAddedServicesIds);
							ddmShoppingCartDao.modify(shoppingCart);
							//拆分购物车
							separateDdmShoppingCart(shoppingCart);
						}else {
							shoppingCart.setShoppingCartState(ShoppingCartState.NotSet);
							shoppingCart.setValueAddedServicesIds(valueAddedServicesIds);
							ddmShoppingCartDao.modify(shoppingCart);
							//拆分购物车
							separateDdmShoppingCart(shoppingCart);

						}
					}

				}

		return CodeContent.getModelByCode(1, "success", getSelectPrice( model,loginUser));
	}

/*
*zlq
* 数量大于1个，并且选择了增值服务，将数量拆分开
 */
	private void separateDdmShoppingCart(DdmShoppingCart ddmShoppingCart){
		if(!StringUtils.isEmpty(ddmShoppingCart.getValueAddedServicesIds())){
			int count=ddmShoppingCart.getCount();
			if(count>1){
				ddmShoppingCart.setCount(1);
				ddmShoppingCartDao.modify(ddmShoppingCart);
					DdmShoppingCart newDdmShoppingCart=new DdmShoppingCart();
					newDdmShoppingCart.setUserId(ddmShoppingCart.getUserId());
					newDdmShoppingCart.setGoodsId(ddmShoppingCart.getGoodsId());
					newDdmShoppingCart.setMemberPrice(ddmShoppingCart.getMemberPrice());
					newDdmShoppingCart.setDdPrice(ddmShoppingCart.getDdPrice());
					newDdmShoppingCart.setCount(count-1);
					newDdmShoppingCart.setShoppingCartState(ShoppingCartState.Valid);
					newDdmShoppingCart.setSpecificationId(ddmShoppingCart.getSpecificationId());
					newDdmShoppingCart.setCreateTime(new Date());
					newDdmShoppingCart.setCreateUserId(ddmShoppingCart.getCreateUserId());
					ddmShoppingCartDao.add(newDdmShoppingCart);
			}
		}

	}

	/*
*zlq
* 用户修改购物车
*  @param  token
*  @param  id:
*  @param  count: 数量
 */
	public  String modifyCount(ModelMap model, String token,String id,String count){

		if (StringUtils.isEmpty(token)) {
			return CodeContent.getModelByCode(-1, "", model);
		}
		User loginUser = userDao.getByToken(token);
		if (loginUser == null) {
			return CodeContent.getModelByCode(-1, "", model);
		}
		if (!NumberUtils.isDigits(id)) {
			return CodeContent.getModelByCode(0, "ID不能为空", model);
		}
		if (!NumberUtils.isDigits(count)) {
			return CodeContent.getModelByCode(0, "数量不能为空", model);
		}
		if(Integer.parseInt(count)<1){
			return CodeContent.getModelByCode(0, "数量不能小于1", model);
		}
		DdmShoppingCart shoppingCart=ddmShoppingCartDao.getById(Integer.parseInt(id));
		if(shoppingCart==null){
			return CodeContent.getModelByCode(0, "不存在的数据", model);
		}
		shoppingCart.setCount(Integer.parseInt(count));
		ddmShoppingCartDao.modify(shoppingCart);
		//拆分购物车
		separateDdmShoppingCart(shoppingCart);
		return CodeContent.getModelByCode(1, "success", getSelectPrice(model,loginUser));
	}
	/*
*zlq
* 用户全选购物车
*  @param  token
*  @param  isSelect: 是否选择 ：true：false
*
*/
	public  String allSelect(ModelMap model, String token,boolean isSelect){
		if (StringUtils.isEmpty(token)) {
			return CodeContent.getModelByCode(-1, "", model);
		}
		User loginUser = userDao.getByToken(token);
		if (loginUser == null) {
			return CodeContent.getModelByCode(-1, "", model);
		}
		DdmShoppingCart shoppingCart=new DdmShoppingCart();
		List<String > shoppingCartStateList =new ArrayList<String>();
		shoppingCartStateList.add(String.valueOf(ShoppingCartState.Valid.getIntValue()));
		shoppingCartStateList.add(String.valueOf(ShoppingCartState.NotSet.getIntValue()));
		shoppingCart.setShoppingCartStateList(shoppingCartStateList);
		shoppingCart.setUserId(loginUser.getId());
		List <DdmShoppingCart> ddmShoppingCartList=ddmShoppingCartDao.queryPageView(-1, -1,shoppingCart).getRecords();
		for(DdmShoppingCart shoppingCart1:ddmShoppingCartList){
			if(isSelect){
				shoppingCart1.setShoppingCartState(ShoppingCartState.Valid);
			}else {
				shoppingCart1.setShoppingCartState(ShoppingCartState.NotSet);
			}
			ddmShoppingCartDao.modify(shoppingCart1);
		}
		return CodeContent.getModelByCode(1, "success", getSelectPrice( model,loginUser));
	}

	private ModelMap getSelectPrice(ModelMap model,User loginUser){
		DdmShoppingCart shoppingCart =new DdmShoppingCart();
		shoppingCart.setUserId(loginUser.getId());
		shoppingCart.setShoppingCartState(ShoppingCartState.Valid);
		PageView pageView=ddmShoppingCartDao.queryPageView(-1, -1,shoppingCart);
		List<ModelMap>  modelMapList1=convertList(pageView.getRecords());
		BigDecimal totalMoney =new BigDecimal("0.00");
		int selectCount=0;
		for(int i=0;i<modelMapList1.size();i++){
			if(modelMapList1.get(i).get("isSelect").toString().equals("true")){
				BigDecimal totalMoney1 =new BigDecimal(modelMapList1.get(i).get("memberPrice").toString());
				totalMoney1=totalMoney1.multiply(new BigDecimal(modelMapList1.get(i).get("count").toString()));
				totalMoney=totalMoney.add(totalMoney1);
				selectCount++;

				List<ModelMap>  valueAddedServicesList= (List<ModelMap>)modelMapList1.get(i).get("valueAddedServicesList");
				for(int x=0;x<valueAddedServicesList.size();x++){
					if(valueAddedServicesList.get(x).get("isSelect").toString().equals("true")){
						BigDecimal totalMoney2 =new BigDecimal(valueAddedServicesList.get(x).get("price").toString());
						totalMoney=totalMoney.add(totalMoney2);
					}
				}
			}

		}
		model.put("totalMoney",totalMoney);
		model.put("rowCount",selectCount);
		return model;
	}

	private String removeRepetition(String strss){
		String [] strs=strss.split(",");
		List<String > strsList=new ArrayList<String>();
		StringBuffer stringBuffer=new StringBuffer();
		for(String str:strs){
			if(!strsList.contains(str)){
				strsList.add(str);
			}
		}
		for(int i=0;i<strsList.size();i++){
			stringBuffer.append(strsList.get(i));
			if(i!=strsList.size()-1){
				stringBuffer.append(",");
			}

		}

		return stringBuffer.toString();
	}
}